package leetcode.biweekly.week77;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution2 implements IDebug {

	public int minimumAverageDifference(int[] nums) {
		int len = nums.length;
		long[] sums = new long[len];
		sums[0] = nums[0];
		for (int i = 1; i < sums.length; i++) {
			sums[i] = sums[i - 1] + nums[i];
		}
		long min = Integer.MAX_VALUE;
		int index = 0;
		for (int i = 0; i < sums.length; i++) {
			long cur = len - i - 1 == 0 ? sums[i] / (i + 1)
					: Math.abs(sums[i] / (i + 1) - (sums[len - 1] - sums[i]) / (len - i - 1));
			if (cur < min) {
				min = cur;
				index = i;
			}
		}
		return index;
	}

	@Override
	public void debug4() {
		H.compare(0, this.minimumAverageDifference(H.str2array3("[1,2,3,4,5]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
